
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String[] args){
		Student[] students={	new Student("babyA",90),
					new Student("babyB",80),
					new Student("babyC",70),
					new Student("babyD",60)};



		try{
			File file=new File(args[0]);
			RandomAccessFile randomAccessFile=new RandomAccessFile(file,"rw");

			for(int i=0;i<students.length;i++){
				randomAccessFile.writeChars(students[i].getName());
				randomAccessFile.writeInt(students[i].getScore());
			}

			Scanner scanner=new Scanner(System.in);
			System.out.print("which number would you like?");

			int num=scanner.nextInt();

			randomAccessFile.seek((num-1)*Student.size());

			Student student=new Student();

			student.setName(readName(randomAccessFile));
			student.setScore(randomAccessFile.readInt());

			System.out.println("name="+student.getName());
			System.out.println("score="+student.getScore());

			randomAccessFile.close();

		}
		catch(ArrayIndexOutOfBoundsException e){
			System.out.println("must input path");

		}
		catch(IOException e){
			e.printStackTrace();
		}
	}




	private static String readName(RandomAccessFile randomaccessfile)throws IOException{
		char[] name=new char[15];
		for(int i=0;i<name.length;i++){
			name[i]=randomaccessfile.readChar();
		}

		return new String(name).replace("\0"," ");

	}
}